<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    canvas {
      margin-left: 30%;
      border: 1px solid #000000;
    }
  </style>
  <body>
    <canvas width="500" height="500" id="myCanvas"></canvas>
  </body>
  <script>
    var c = document.getElementById('myCanvas')
    var ctx = c.getContext('2d')
    var c = document.getElementById('myCanvas')
    var ctx = c.getContext('2d')
    ctx.translate(100, 100)
    ctx.rotate((Math.PI / 180) * 45)
    ctx.moveTo(30, 30)
    ctx.lineTo(200, 30)
    ctx.lineTo(160, 100)
    ctx.lineTo(70, 100)
    ctx.lineTo(30, 30)
    ctx.fill()
    // 创建渐变
    // var grd = ctx.createRadialGradient(175, 175, 5, 175, 175, 80)
    // grd.addColorStop(0, 'red')
    // grd.addColorStop(0.3, 'blue')
    // grd.addColorStop(0.6, 'green')
    // grd.addColorStop(1, 'white')

    // // 填充渐变
    // ctx.fillStyle = grd
    // // ctx.strokeStyle = '#000'
    // // ctx.stroke()
    // ctx.strokeRect(10, 10, 350, 350)
    // ctx.fillRect(10, 10, 350, 350)
  </script>
</html>
